package com.helper.dream.a361phonehelper.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.helper.dream.a361phonehelper.R;
import com.helper.dream.a361phonehelper.fragment.detail.ImageAndTextFragment;
import com.helper.dream.a361phonehelper.fragment.detail.VideoFragment;

import java.util.List;


/**
 * Created by Administrator on 2016/12/19.
 */

public class RedianFragment extends Fragment {
    public static final String CLASS_KIND_KEY = "c";
    String[] c = {"youlike", "newhot", "video", "fun", "science", "car", "militery", "economy", "sport", "social", "funny", "health", "education"
    ,"duanzi", "beauty", "live"};
    String[] tabs = {"推荐", "热点", "视频", "娱乐", "科技", "汽车", "军事", "财经","体育", "社会", "搞笑", "健康", "教育", "段子", "美女", "直播"};
    TabLayout tabLayout;
    ViewPager viewPager;
    List<ImageAndTextFragment> fs;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_hotspot_layout, container, false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        intView(view);
        loadData();
        addListener();
    }

    private void addListener() {

    }

    private void loadData() {
        viewPager.setAdapter(new FragmentPagerAdapter(getActivity().getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                Bundle bundle = new Bundle();
                bundle.putString(CLASS_KIND_KEY, c[position]);

                String key = c[position];
                switch (key){
                    case "video":{
                        VideoFragment f = new VideoFragment();
                        f.setArguments(bundle);
                        return f;
                    }
                }
                ImageAndTextFragment fragment = new ImageAndTextFragment();
                fragment.setArguments(bundle);
                return fragment;
            }
            @Override
            public int getCount() {
                return tabs.length;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return tabs[position];
            }
        });
        tabLayout.setupWithViewPager(viewPager);
    }

    private void intView(View view) {
        tabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
        viewPager = (ViewPager) view.findViewById(R.id.view_pager);
    }
}
